Completed
Push — master ( 2115c9...bdfcbe )
by
unknown
02:14
created

sql.js ➔ cleanRequest   C

Complexity

Conditions 12
Paths 4

Size

Total Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
nc 4
dl 0
loc 46
rs 5.15
c 0
b 0
f 0
nop 2

How to fix   Complexity   

Complexity

Complex classes like sql.js ➔ cleanRequest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
import {parse} from 'node-sqlparser'
2
import {Promise} from 'es6-promise'
3
import path from 'path'
4
import {
5
  config,
6
  Manager,
7
  FileParser,
0 ignored issues
show
Unused Code introduced by
The variable FileParser seems to be never used. Consider removing it.
Loading history...
8
  getAttr
9
} from '../../'
10
11
export function cleanRequest(str, jsonPage) {
0 ignored issues
show
Unused Code introduced by
The parameter jsonPage is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
12
  var matchFrom = /from .(.*?) /
13
  var matchVariable = /{{([a-zA-Z]*)}}/
14
15
  var matchFromExec = matchFrom.exec(str)
16
  if(typeof matchFromExec !== 'undefined' && matchFromExec !== null
17
    && typeof matchFromExec[1] !== 'undefined' && matchFromExec[1] !== null) {
18
19
    var fromMatch
20
    var toReplace = matchFromExec[1]
21
    while (fromMatch = matchVariable.exec(toReplace)) {
22
      try {
23
        var value = eval('jsonPage.' + fromMatch[1])
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
24
        if(typeof value !== 'undefined' && value !== null) {
25
          toReplace = toReplace.replace('{{' + fromMatch[1] + '}}', value)
26
        }else {
27
          toReplace = toReplace.replace('{{' + fromMatch[1] + '}}', '')
28
        }
29
      }catch(e) {
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
30
      }
31
    }
32
33
    str = str.replace(matchFromExec[1], toReplace)
34
  }
35
36
  var from = /from ([\S\s]+)/.exec(str)
37
38
  var matches = from
39
  if(matches[1]) {
40
    var res = matches[1]
41
    var splitAttr = [' where ', ' order by ', ' limit ', ' WHERE ', ' ORDER BY ', ' LIMIT ']
42
    for(var i = 0; i < splitAttr.length; i++) {
43
      if(res.indexOf(splitAttr[i]) > -1) {
44
        res = res.substring(0, res.indexOf(splitAttr[i]))
45
      }
46
    }
47
    var escapedFrom = res.replace(/\//g, '___abe___')
48
    escapedFrom = escapedFrom.replace(/\./g, '___abe_dot___')
49
    escapedFrom = escapedFrom.replace(/-/g, '___abe_dash___')
50
    str = str.replace(res, escapedFrom)
51
  }
52
53
  str = str.replace(/``/g, '\'\'')
54
55
  return str
56
}
57
58
export function handleSqlRequest(str, jsonPage) {
59
  var req = cleanRequest(str, jsonPage)
60
  var request = parse(req)
61
  var reconstructSql = ''
62
63
  // SQL TYPE
64
  var type = ''
65
  if(typeof request.type !== 'undefined' && request.type !== null) {
66
    type = request.type
67
  }
68
  reconstructSql += `${type} `
69
70
  // SQL COLUMNS
71
  var columns = []
72
  if(typeof request.columns !== 'undefined' && request.columns !== null) {
73
    if(request.columns === '*') {
74
      columns.push('*')
75
    }else {
76
      Array.prototype.forEach.call(request.columns, (item) => {
77
        columns.push(item.expr.column)
78
      })
79
    }
80
  }
81
  reconstructSql += `${JSON.stringify(columns)} `
82
83
  // SQL FROM
84
  var from = []
85
  if(typeof request.from !== 'undefined' && request.from !== null) {
86
87
    Array.prototype.forEach.call(request.from, (item) => {
88
      from.push(item.table)
89
    })
90
  }else {
91
    from.push('*')
92
  }
93
  reconstructSql += `from ${JSON.stringify(from)} `
94
95
  var where
96
  if(typeof request.where !== 'undefined' && request.where !== null) {
97
    where = request.where
98
    // where = recurseWhere(request.where)
99
    // reconstructSql += 'where '
100
    // Array.prototype.forEach.call(where, (w) => {
101
    //   reconstructSql += `${w.operator} ${w.left} ${w.compare} ${w.right} `
102
    // })
103
  }
104
105
  var limit = -1
106
  if(typeof request.limit !== 'undefined' && request.limit !== null) {
107
    limit = request.limit[request.limit.length - 1].value
108
  }
109
110
  var orderby
111
  if(typeof request.orderby !== 'undefined' && request.orderby !== null && request.orderby.length > 0) {
112
    orderby = {
113
      column: request.orderby[0].expr.column,
114
      type: request.orderby[0].type
115
    }
116
    reconstructSql += `ORDER BY ${orderby.column} ${orderby.type} `
117
  }
118
119
  return {
120
    type: type,
121
    columns: columns,
122
    from: from,
123
    where: where,
0 ignored issues
show
Bug introduced by
The variable where does not seem to be initialized in case typeof request.where !=... request.where !== null on line 96 is false. Are you sure this can never be the case?
Loading history...
124
    string: reconstructSql,
125
    limit: limit,
126
    orderby: orderby
0 ignored issues
show
Bug introduced by
The variable orderby does not seem to be initialized in case typeof request.orderby ...uest.orderby.length > 0 on line 111 is false. Are you sure this can never be the case?
Loading history...
127
  }
128
}
129
130
export function sortByDateDesc(a, b) {
131
  var dateA = new Date(a.date)
132
  var dateB = new Date(b.date)
133
  if(dateA < dateB) {
134
    return 1
135
  }else if(dateA > dateB) {
136
    return -1
137
  }
138
  return 0
139
}
140
141
export function shuffle(array) {
142
  var currentIndex = array.length, temporaryValue, randomIndex
143
144
  // While there remain elements to shuffle...
145
  while (0 !== currentIndex) {
146
147
    // Pick a remaining element...
148
    randomIndex = Math.floor(Math.random() * currentIndex)
149
    currentIndex -= 1
150
151
    // And swap it with the current element.
152
    temporaryValue = array[currentIndex]
153
    array[currentIndex] = array[randomIndex]
154
    array[randomIndex] = temporaryValue
155
  }
156
157
  return array
158
}
159
160
export function sortByDateAsc(a, b) {
161
  var dateA = new Date(a.date)
162
  var dateB = new Date(b.date)
163
  if(dateA > dateB) {
164
    return 1
165
  }else if(dateA < dateB) {
166
    return -1
167
  }
168
  return 0
169
}
170
171
export function getDataSource(str) {
172
  var res = str.substring(str.indexOf('source=') + 8, str.length)
173
174
  var reg = /([^'"]*=[\s\S]*?}})/g
175
  var matches = res.match(reg)
176
  if(typeof matches !== 'undefined' && matches !== null) {
177
    Array.prototype.forEach.call(matches, (match) => {
178
      res = res.replace(match, '')
179
    })
180
  }else {
181
    res = res.replace('}}', '')
182
  }
183
184
  return res.substring(0, res.length-1)
185
}
186
187
/**
188
 * replaces escaped characters with the right ones
189
 * @param  {String} statement the from clause
190
 * @return {String}           the from sanitized
191
 */
192
export function sanitizeFromStatement(statement){
193
  var from = ''
194
195
  if(typeof statement !== 'undefined' && statement !== null) {
196
    from = statement[0].replace(/___abe_dot___/g, '.')
197
    from = from.replace(/___abe___/g, '/')
198
    from = from.replace(/___abe_dash___/g, '-')
199
  }
200
201
  return from
202
}
203
204
/**
205
 * calculate the directory to analyze from the from clause
206
 * @param  {String} statement the from clause
207
 * @param  {String} tplPath   the path from the template originator
208
 * @return {string}           the directory to analyze
209
 */
210
export function getFromDirectory(statement, tplPath){
211
  var pathFromDir = ''
212
  if(typeof tplPath === 'undefined' || tplPath === null || tplPath === ''){
213
    tplPath = '/'
214
  }
215
216
  if(statement === '' || statement === '*' || statement === '/') {
217
    pathFromDir = path.join(config.root, config.data.url)
218
  }else if(statement === './') {
219
    pathFromDir = path.join(config.root, config.data.url, tplPath)
220
  }else if(statement.indexOf('/') === 0) {
221
    pathFromDir = path.join(config.root, config.data.url, statement)
222
  }else if(statement.indexOf('/') !== 0) {
223
    pathFromDir = path.join(config.root, config.data.url, tplPath, statement)
224
  }
225
226
  return pathFromDir
227
}
228
229
export function executeOrderByClause(files, orderby){
230
  if(typeof orderby !== 'undefined' && orderby !== null) {
231
    if(orderby.column.toLowerCase() === 'random') {
232
      shuffle(files)
233
    }else if(orderby.column.toLowerCase() === 'date') {
234
      if(orderby.type === 'ASC') {
235
        files.sort(sortByDateAsc)
236
      }else if(orderby.type === 'DESC') {
237
        files.sort(sortByDateDesc)
238
      }
239
    }
240
  }
241
242
  return files
243
}
244
245
export function executeFromClause(statement, pathFromClause){
246
  var from = sanitizeFromStatement(statement)
247
248
  // if the from clause ends with a dot, we won't recurse the directory analyze
249
  if(from.slice(-1) === '.'){
250
    from = from.slice(0, -1)
251
  }
252
  
253
  var fromDirectory = getFromDirectory(from, pathFromClause)
254
255
  var list = Manager.instance.getList()
256
  var files_array = list.filter((element, index) => {
0 ignored issues
show
Unused Code introduced by
The parameter index is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
257
    if(element.publish) {
258
      if (element.path.indexOf(fromDirectory) > -1) {
259
        return true
260
      }
261
    }
262
    return false
263
  })
264
  return files_array
265
}
266
267
export function execQuery(pathQuery, match, jsonPage) {
268
  var res
269
  var files
270
  var request = handleSqlRequest(getAttr(match, 'source'), jsonPage)
271
272
  files = executeFromClause(request.from, pathQuery)
273
  files = executeOrderByClause(files, request.orderby)
274
  res = executeWhereClause(files, request.where, request.limit, request.columns, jsonPage)
275
276
  return res
277
}
278
279
export function executeQuerySync(pathQuerySync, match, jsonPage) {
280
  return execQuery(pathQuerySync, match, jsonPage)
281
}
282
283
export function executeQuery(pathexecuteQuery, match, jsonPage) {
284
  var p = new Promise((resolve) => {
285
    var res = execQuery(pathexecuteQuery, match, jsonPage)
286
    resolve(res)
287
  }).catch(function(e) {
288
    console.error(e)
289
  })
290
291
  return p
292
}
293
294
/**
295
 * check if a given string an url, string json, file url, abe sql request
296
 * 
297
 * get('http://google.com')
298
 * get('{"test":"test"}')
299
 * get('select * from ../')
300
 * get('test')
301
 * 
302
 * @param  {String} str 
303
 * @return {String} url | request | value | file | other
304
 */
305
export function getSourceType(str) {
306
  if(/http:\/\/|https:\/\//.test(str)) {
307
    return 'url'
308
  }
309
310
  if(/select[\S\s]*?from/.test(str)) {
311
    return 'request'
312
  }
313
314
  try {
315
    JSON.parse(str)
316
    return 'value'
317
  }catch(e) {
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
318
319
  }
320
321
  if(/\.json/.test(str)) {
322
    return 'file'
323
  }
324
325
  return 'other'
326
}
327
328
export function executeWhereClause(files, wheres, maxLimit, columns, jsonPage){
329
  var res = []
330
  var limit = 0
331
332
  for(let file of files) {
333
    if(limit < maxLimit || maxLimit === -1) {
334
      if(typeof wheres !== 'undefined' && wheres !== null) {
335
336
        if(!recurseWhere(wheres, file.publish, jsonPage)) {
337
          var json = JSON.parse(JSON.stringify(file.publish))
338
          var jsonValues = {}
339
340
          if(typeof columns !== 'undefined' && columns !== null && columns.length > 0 && columns[0] !== '*') {
341
            
342
            Array.prototype.forEach.call(columns, (column) => {
343
              if(typeof json[column] !== 'undefined' && json[column] !== null) {
0 ignored issues
show
Bug introduced by
The variable json is changed as part of the for-each loop for example by JSON.parse(JSON.stringify(file.publish)) on line 337. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
344
                jsonValues[column] = json[column]
0 ignored issues
show
Bug introduced by
The variable jsonValues is changed as part of the for-each loop for example by {} on line 338. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
345
              }
346
            })
347
            jsonValues['abe_meta'] = json['abe_meta']
348
          }else {
349
            jsonValues = json
350
          }
351
352
          res.push(jsonValues)
353
          limit++
354
        }
355
      }
356
    } else {
357
      break
358
    }
359
  }
360
361
  return res
362
}
363
364
export function getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc) {
0 ignored issues
show
Unused Code introduced by
The parameter jsonDoc is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter jsonOriginalDoc is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
365
  var regexIsVariable = /^{{(.*)}}$/
366
  var value
367
  var compare
368
369
  try {
370
    var variableLeft = where.left.column
371
    var checkIfLeftIsAVariable = regexIsVariable.exec(variableLeft)
372
    if(typeof checkIfLeftIsAVariable !== 'undefined' && checkIfLeftIsAVariable !== null && checkIfLeftIsAVariable.length > 0) {
373
      variableLeft = checkIfLeftIsAVariable[1]
374
    }
375
    value = eval('jsonDoc.' + variableLeft)
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
376
  }catch(e) {
377
    // console.log('e', e)
378
  }
379
  
380
  if(where.operator === 'IN' || where.operator === 'NOT IN') {
381
    compare = []
382
    Array.prototype.forEach.call(where.right.value, (right) => {
383
      var matchRightVariable = regexIsVariable.exec(right.column)
384
      if(typeof matchRightVariable !== 'undefined' && matchRightVariable !== null && matchRightVariable.length > 0) {
385
        try {
386
          var jsonOriginalValues = eval('jsonOriginalDoc.' + matchRightVariable[1])
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
387
          Array.prototype.forEach.call(jsonOriginalValues, (jsonOriginalValue) => {
0 ignored issues
show
Unused Code introduced by
The parameter jsonOriginalValue is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
388
            compare.push(eval('jsonOriginalValue.' + where.left.column))
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
389
          })
390
        }catch(e) {}
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
391
      }
392
      else{
393
        compare.push(right.column)
394
      }
395
    })
396
  }else {
397
    compare = where.right.column
398
    var matchRightVariable = regexIsVariable.exec(compare)
399
400
    if(typeof matchRightVariable !== 'undefined' && matchRightVariable !== null && matchRightVariable.length > 0) {
401
      try {
402
        var shouldCompare = eval('jsonOriginalDoc.' + matchRightVariable[1])
0 ignored issues
show
Security Performance introduced by
Calls to eval are slow and potentially dangerous, especially on untrusted code. Please consider whether there is another way to achieve your goal.
Loading history...
403
        if(typeof shouldCompare !== 'undefined' && shouldCompare !== null) {
404
          compare = shouldCompare
405
        }else {
406
          compare = null
407
        }
408
      }catch(e) {
409
        compare = null
410
      }
411
    }
412
  }
413
414
  return {
415
    left: value,
0 ignored issues
show
Bug introduced by
The variable value does not seem to be initialized in case var variableLeft = where.left.column on line 370 throws an error. Are you sure this can never be the case?
Loading history...
416
    right: compare
417
  }
418
}
419
420
export function recurseWhere(where, jsonDoc, jsonOriginalDoc) {
421
  var shouldAdd = true
0 ignored issues
show
Unused Code introduced by
The variable shouldAdd seems to be never used. Consider removing it.
Loading history...
422
  var isNotLeftCorrect = false
0 ignored issues
show
Unused Code introduced by
The assignment to variable isNotLeftCorrect seems to be never used. Consider removing it.
Loading history...
423
  var isNotRightCorrect = false
0 ignored issues
show
Unused Code introduced by
The assignment to variable isNotRightCorrect seems to be never used. Consider removing it.
Loading history...
424
  var isNotCorrect = false
0 ignored issues
show
Unused Code introduced by
The assignment to variable isNotCorrect seems to be never used. Consider removing it.
Loading history...
425
426
  switch(where.operator) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
427
  case '=':
428
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
429
    isNotCorrect = !(values.left === values.right)
430
    break
431
  case '!=':
432
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 428. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
433
    isNotCorrect = !(values.left !== values.right)
434
    break
435
  case '>':
436
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 428. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
437
    isNotCorrect = !(values.left > values.right)
438
    break
439
  case '>=':
440
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 428. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
441
    isNotCorrect = !(values.left >= values.right)
442
    break
443
  case '<':
444
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 428. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
445
    isNotCorrect = !(values.left < values.right)
446
    break
447
  case '<=':
448
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 428. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
449
    isNotCorrect = !(values.left <= values.right)
450
    break
451
  case 'LIKE':
452
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 428. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
453
    isNotCorrect = !(values.left && values.left.indexOf(values.right) > -1)
454
    break
455
  case 'NOT LIKE':
456
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 428. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
457
    isNotCorrect = !(values.left && values.left.indexOf(values.right) === -1)
458
    break
459
  case 'AND':
460
    isNotLeftCorrect = recurseWhere(where.left, jsonDoc, jsonOriginalDoc)
461
    isNotRightCorrect = recurseWhere(where.right, jsonDoc, jsonOriginalDoc)
462
    isNotCorrect = (isNotLeftCorrect || isNotRightCorrect) ? true : false
463
    break
464
  case 'OR':
465
    isNotLeftCorrect = recurseWhere(where.left, jsonDoc, jsonOriginalDoc)
466
    isNotRightCorrect = recurseWhere(where.right, jsonDoc, jsonOriginalDoc)
467
    isNotCorrect = (isNotLeftCorrect && isNotRightCorrect) ? true : false
468
    break
469
  case 'IN':
470
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 428. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
471
    isNotCorrect = true
472
    Array.prototype.forEach.call(values.right, (right) => {
473
      if(values.left === right) {
474
        isNotCorrect = false
475
      }
476
    })
477
    break
478
  case 'NOT IN':
479
    var values = getWhereValuesToCompare(where, jsonDoc, jsonOriginalDoc)
0 ignored issues
show
Comprehensibility Naming Best Practice introduced by
The variable values already seems to be declared on line 428. Consider using another variable name or omitting the var keyword.

This check looks for variables that are declared in multiple lines. There may be several reasons for this.

In the simplest case the variable name was reused by mistake. This may lead to very hard to locate bugs.

If you want to reuse a variable for another purpose, consider declaring it at or near the top of your function and just assigning to it subsequently so it is always declared.

Loading history...
480
    isNotCorrect = false
481
    Array.prototype.forEach.call(values.right, (right) => {
482
      if(values.left === right) {
483
        isNotCorrect = true
484
      }
485
    })
486
    break
487
  }
488
  return isNotCorrect
489
}